//
//  LMmicoBlogFrame.m
//  14微博
//
//  Created by apple on 15/8/2.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "LMmicroBlogFrame.h"
#import "LMmicroBlog.h"
@implementation LMmicroBlogFrame
//计算文字的大小
- (CGSize)sizeWithText:(NSString *)text maxsize:(CGSize) maxSize fontSize:(CGFloat) fontSize
{
    CGSize fontsize = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
    return fontsize;
}


- (void)setMicroBlog:(LMmicroBlog *)microBlog
{
    _microBlog = microBlog;
    
    
    //设置icon的Frame
    CGFloat margin = 10;
    CGFloat iconX = margin;
    CGFloat iconY = margin;
    CGFloat iconW = 30;
    CGFloat iconH = 30;
    _iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    
    //设置name的Frame
    CGFloat nameX = CGRectGetMaxX(_iconFrame)+margin;
    CGFloat nameY = iconW/2 + margin;
    CGSize nameWH =[self sizeWithText:self.microBlog.name maxsize:CGSizeMake(MAXFLOAT, MAXFLOAT) fontSize:13];
    _nameFrame = CGRectMake(nameX, nameY, nameWH.width, nameWH.height);
    
    //设置vip的Frame
    CGFloat vipX = CGRectGetMaxX(_nameFrame);
    CGFloat vipY = nameY;
    CGFloat vipW = 14;
    CGFloat vipH = 14;
    _vipFrame = CGRectMake(vipX, vipY, vipW, vipH);
    
    //设置text的Frame
    CGFloat textX = margin;
    CGFloat textY = CGRectGetMaxY(_iconFrame)+margin;
   //CGSize textWH = [label sizeThatFits:CGSizeMake(label.frame.size.width, MAXFLOAT)];
    CGSize textWH = [self sizeWithText:self.microBlog.text maxsize:CGSizeMake(280, MAXFLOAT) fontSize:10];
    _textFrame = CGRectMake(textX, textY, textWH.width  ,textWH.height);
    
    if (self.microBlog.picture) {
        CGFloat pictureX = margin;
        CGFloat pictureY = CGRectGetMaxY(_textFrame)+margin;
        CGFloat pictureW = 100;
        CGFloat pictureH = 100;
        _pictureFrame = CGRectMake(pictureX, pictureY, pictureW, pictureH);
        _rowheight = CGRectGetMaxY(_pictureFrame)+margin;
    }else
    {
    _rowheight = CGRectGetMaxY(_textFrame)+margin;
    }
}
@end
